from django.contrib.auth.models import Group
from rest_framework.response import Response
from rest_framework.viewsets import ModelViewSet

from apps.meiduo_admin.serializers.admin import AdminSerializer
from apps.meiduo_admin.serializers.users import UserSerializer
from apps.meiduo_admin.utils import PageNum
from apps.users.models import User
from apps.meiduo_admin.serializers.groups import GroupViewSerializer

############用户管理#############
############获取用户,保存用户##################
class AdminView(ModelViewSet):

    # 指定序列化器
    serializer_class = AdminSerializer
    # 指定查询集
    queryset = User.objects.filter(is_staff=True)
    #指定分页器
    pagination_class = PageNum


    #####获取管理员用户分组信息
    def groups(self,request):
        # 1.查询分组信息
        data = Group.objects.all()
        # 2.返回分组
        ser = GroupViewSerializer(data,many=True)
        return Response(ser.data)